﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.model;

namespace l1cs.server.clientpackets
{
    public class C_CallPlayer : ClientBasePacket
    {
        private const String _C_CALL = "[C] C_Call";

        private static Logger _log = Logger.getLogger( typeof( C_CallPlayer ).FullName );

        public C_CallPlayer( byte[] decrypt, ClientThread client )
            : base( decrypt )
        {
            L1PcInstance pc = client.getActiveChar();

            if ( !pc.isGm() )
            {
                return;
            }

            String name = readS();
            if ( name.Length == 0 )
            {
                return;
            }

            L1PcInstance target = L1World.getInstance().getPlayer( name );

            if ( target == null )
            {
                return;
            }

            L1Location loc =
                    L1Location.randomLocation( target.getLocation(), 1, 2, false );
            L1Teleport.teleport( pc, loc.getX(), loc.getY(), target.getMapId(), pc
                    .getHeading(), false );
        }

        override
        public String getType()
        {
            return _C_CALL;
        }
    }
}